﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using FormProcessingTool;

namespace RegistTool
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "打开注册文件";
            openFileDialog.Filter = "KEY文件|*.key";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog.FileName;
            }
            else
            {
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string localFileName = string.Concat(Environment.CurrentDirectory,Path.DirectorySeparatorChar,RegistFileHelper.ComputerInfofile);

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("请选择用户证书");
                return;
            }
            if (textBox1.Text != localFileName)
                File.Copy(textBox1.Text, localFileName, true);
            string computer = RegistFileHelper.ReadComputerInfoFile();
            EncryptionHelper help = new EncryptionHelper(EncryptionKeyEnum.KeyB);
            string md5String = help.GetMD5String(computer);
            string registInfo = help.EncryptString(md5String);
            RegistFileHelper.WriteRegistFile(registInfo);
            MessageBox.Show("注册证书已生成");
        }
    }
}
